﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;

using WpfFlashControl;

namespace Min
{
	public partial class Window1
	{
        
		public Window1()
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
		}

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Grid grid = LayoutRoot.FindName("SubMenu") as Grid;
            grid.Visibility = Visibility.Visible;

            FadeInOut(grid, true);
        }

        private void Flash_Button_Click(object sender, RoutedEventArgs e)
        {
            //Button button = LayoutRoot.FindName("FlashClose") as Button;
            //button.Visibility = Visibility.Visible;

            //WpfFlashControl.UserControl1 flashCtrl = LayoutRoot.FindName("flashCtrl") as WpfFlashControl.UserControl1;
            //flashCtrl.Visibility = Visibility.Visible;

            //string path = Directory.GetCurrentDirectory();

            //string strName = string.Format("file:///{0}\\{1}.swf", path, (sender as Button).Name);
            //flashCtrl.Play(strName);
        }

        private void Flash_Button_Close(object sender, RoutedEventArgs e)
        {
            //WpfFlashControl.UserControl1 flashCtrl = LayoutRoot.FindName("flashCtrl") as WpfFlashControl.UserControl1;

            //Button button = LayoutRoot.FindName("FlashClose") as Button;
            //button.Visibility = Visibility.Hidden;
            //flashCtrl.Visibility = Visibility.Hidden;
            //flashCtrl.Stop();
        }
        
        public void FadeInOut(UIElement Src, bool bIn)
        {
            // Create a storyboard to contain the animations.
            Storyboard storyboard = new Storyboard();
            TimeSpan duration = new TimeSpan(0, 0, 1);

            // Create a DoubleAnimation to fade the not selected option control
            DoubleAnimation animation = new DoubleAnimation();

            if ( bIn == true )
            {
                animation.From = 0.0;
                animation.To = 1.0;
            }
            else
            {
                animation.From = 1.0;
                animation.To = 0.0;
            }

            animation.Duration = new Duration(duration);
            // Configure the animation to target de property Opacity
            Storyboard.SetTargetName(animation, (Src as FrameworkElement).Name);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Control.OpacityProperty));
            // Add the animation to the storyboard
            storyboard.Children.Add(animation);

            // Begin the storyboard
            storyboard.Begin(this);
        }

	}
}